﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HDJ.Framework.Core
{
    public class World 
    {
        private int id;
        public int ID
        {
            get { return id; }
        }
        public LocalEvent localEvent = new LocalEvent();
        //public GameSceneManager sceneManager =null;
        public LocalTypeEvent localTypeEvent;

        /// <summary>
        /// 单例变量数据
        /// </summary>
        protected Dictionary<Type, object> singleData = new Dictionary<Type, object>();
        public World(int id)
        {
            this.id = id;
            //sceneManager = new GameSceneManager(this);
            localTypeEvent = new LocalTypeEvent();
        }
        /// <summary>
        /// 获取单例数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetSingleData<T>() where T : new()
        {
            Type type = typeof(T);
            if (singleData.ContainsKey(type))
            {
                return (T)singleData[type];
            }
            else
            {
                T t = new T();
                singleData.Add(type, t);
                return t;
            }
        }

        public  void Start(string firstSceneName=null)
        {
            //if (!string.IsNullOrEmpty(firstSceneName))
            //{
            //    sceneManager.OpenScene(firstSceneName);
            //}

            OnStart();
        }

        protected virtual void OnStart()
        {

        }
    }
}
